<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Advert extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'advert';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'module_text',
        'status_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            if (!$row['weigh']) {
                $pk = $row->getPk();
                $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
            }
        });
    }

    
    public function getModuleList()
    {
        return [
            //'open' => __('Module open'),
            'index' => __('Module index'),
            //'index_bottom' => __('Module index_bottom'),
            'gxmj' => __('Module gxmj'),
            //'gxmj_bottom' => __('Module gxmj_bottom'),
            'fwhz' => __('Module fwhz'),
            //'fwhz_bottom' => __('Module fwhz_bottom'),
            'bthz' => __('Module bthz'),
            //'bthz_bottom' => __('Module bthz_bottom')
        ];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }


    public function getModuleTextAttr($value, $data)
    {
        $value = $value ?: ($data['module'] ?? '');
        $list = $this->getModuleList();
        return $list[$value] ?? '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }




}
